﻿Imports System.Threading
Imports System.Runtime.InteropServices
Imports System.Reflection
Imports Sy.UI
Imports Sy.Data
Imports Sy.UI.Common
Imports System.Web
Imports System.Text
Imports System.Globalization

Public Class Form3
    Dim dpurl As String
    Dim allasin As String
    Dim uploadxc As Thread
    Dim myyz As Boolean = False
    Public isworking As Boolean = False
    <DllImport("urlmon.dll", CharSet:=CharSet.Ansi)>
    Private Shared Function UrlMkSetSessionOption(ByVal dwOption As Integer, ByVal pBuffer As String, ByVal dwBufferLength As Integer, ByVal dwReserved As Integer) As Integer
    End Function
    Const URLMON_OPTION_USERAGENT As Integer = &H10000001
    Private Shared defaultUserAgent As String = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36"
    Public Shared Sub AppendUserAgent(ByVal Str As String)
        'If String.IsNullOrEmpty(defaultUserAgent) Then
        '    defaultUserAgent = GetDefaultUserAgent()
        'End If
        'Dim ua As String = defaultUserAgent & Str
        ChangeUserAgent(defaultUserAgent)
    End Sub
    Public Shared Sub ChangeUserAgent(ByVal userAgent As String)
        UrlMkSetSessionOption(URLMON_OPTION_USERAGENT, userAgent, userAgent.Length, 0)
    End Sub
    Private Shared Function GetDefaultUserAgent() As String
        Dim wb As New WebBrowser()
        wb.Navigate("about:blank")
        While wb.IsBusy
            Application.DoEvents()
        End While
        Dim window As Object = wb.Document.Window.DomWindow
        Dim wt As Type = window.[GetType]()
        Dim navigator As Object = wt.InvokeMember("navigator", BindingFlags.GetProperty, Nothing, window, New Object() {})
        Dim nt As Type = navigator.[GetType]()
        Dim userAgent As Object = nt.InvokeMember("userAgent", BindingFlags.GetProperty, Nothing, navigator, New Object() {})
        Return userAgent.ToString()
    End Function
    Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Try
            Dim Create = CreateSQLBuilder(Of TaskList2).CreateSQL()
            DB = New SQLite(Create, Application.StartupPath & "\Config\task2.db")
            TaskList2.AddDB(DB)
            DB.Foreign_keys = True

            'CefWeb2 = CefBrowser.LoadBrowser(Capture.Pnl_Web, "about:_blank")
            CefWeb = CefBrowser.LoadBrowser(Pnl_Web, "about:_blank")
            UIAdapter.ListviewAdapter(Of TaskList2)(ListView2, "序号")
            hb.Items.Add("")
            hb.Items.Add("美元")
            hb.Items.Add("英镑")
            hb.Items.Add("欧元")
            hb.Items.Add("日元")
            hb.Items.Add("加元")
            hb.Items.Add("澳元")
            hb.Items.Add("墨西哥比索")
            hb.Items.Add("兹罗提")
            hb.Items.Add("瑞典克朗")
            hb.Items.Add("印度卢比")
            hb.SelectedIndex = 0
            sb.Items.Add("")
            sb.Items.Add("未知")
            sb.Items.Add("已注册")
            sb.Items.Add("未注册")
            sb.SelectedIndex = 0
            js.Items.Add("")
            js.Items.Add("未知")
            js.Items.Add("是")
            js.Items.Add("否")
            js.SelectedIndex = 0
            fbm.Items.Add("")
            fbm.Items.Add("未知")
            fbm.Items.Add("是")
            fbm.Items.Add("否")
            fbm.SelectedIndex = 0

            Loadtasklist()
            Loadlist("")
        Catch ex As Exception
            MsgBox("程序载入异常，请重试！", MsgBoxStyle.OkOnly, "提示")
        End Try
    End Sub
    Private Sub TabControl1_Selected(sender As Object, e As TabControlEventArgs) Handles TabControl1.Selected
        If e.TabPage.TabIndex = TabPage2.TabIndex Then
            If isworking = True Then
                MsgBox("请先停止任务再筛选")
                TabControl1.SelectedTab = TabPage1
                Exit Sub
            Else
                'Me.AcceptButton = Me.Button8
                Loadlist("")
                Loadtasklist()
            End If
        End If
    End Sub
    Sub Loadtasklist()
        Try
            mytasklist.Items.Clear()
            Dim sql As String = "select distinct Taskname from t_TaskList2;"
            Dim reader As Data.Common.DbDataReader = DB(sql)
            Do While reader.Read
                mytasklist.Items.Add(reader(0).ToString)
            Loop
            reader.Close()
        Catch ex As Exception
            MsgBox("加载数据异常", MsgBoxStyle.OkOnly, "提示")
        End Try
    End Sub
    Sub Loadlist(sqlstr As String)
        Try
            With ListView2
                .Items.Clear()
            End With
            Dim TaskLists = If(sqlstr.IsNotWhiteSpace, TaskList2.LoadWhere(sqlstr), TaskList2.Load())
            Dim i As Long = 1
            For Each TaskList In TaskLists
                Dim a = UIAdapter.GetListViewItem(TaskList, i)
                Dim itm As ListViewItem = ListView2.Items.Add(a) '状态 进度 id
                itm.Tag = TaskList
                'itm = ListView2.Items.Add(i)
                'itm.SubItems.AddRange({TaskList.ObjectDBID, TaskList.Asin, TaskList.Dpurl, CStr(reader.Item("nodebrowser")), CStr(reader.Item("nodename")), CStr(reader.Item("review")), CStr(reader.Item("price")), CStr(reader.Item("shipfee")), CStr(reader.Item("totalprice")), CStr(reader.Item("currency")), CStr(reader.Item("bsr")), CStr(reader.Item("brand")), CStr(reader.Item("isreg")), CStr(reader.Item("ischina")), CStr(reader.Item("totalmark")), CStr(reader.Item("c_time"))})
                i = i + 1
            Next
        Catch ex As Exception
            MsgBox("加载数据异常", MsgBoxStyle.OkOnly, "提示")
        End Try
    End Sub


    Private Sub btstart_Click(sender As Object, e As EventArgs) Handles btstart.Click
        'Dim html = gethtml("https://www.amazon.com/gp/delivery/ajax/address-change.html")
        'Thread.Sleep(1000)
        'Dim html2 = gethtml("https://www.amazon.com/")

        'Getposthtmln.getnewhtml("https://www.amazon.com/gp/delivery/ajax/address-change.html", "", "", "")
        'Thread.Sleep(1000)
        'Getposthtmln.getnewhtml("https://www.amazon.com/", "GET", "", mycookie.Text)
        'System.Net.ServicePointManager.DefaultConnectionLimit = 65500
        'System.Net.ServicePointManager.MaxServicePointIdleTime = 3600 * 1000
        Try
            If (listurl.Text = "" Or InStr(listurl.Text.ToLower, "www.amazon") <= 0) And iscontinue.Checked = False Then
                btstart.Enabled = True
                btend.Enabled = False
                MsgBox("请输入正确的列表页网址！", MsgBoxStyle.OkOnly, "提示")
                Exit Sub
            End If
            If usecookie.Checked And listurl.Text = "" Then
                btstart.Enabled = True
                btend.Enabled = False
                MsgBox("COOKIE不能为空！", MsgBoxStyle.OkOnly, "提示")
                Exit Sub
            End If
            If taskname.Text = "" Then
                btstart.Enabled = True
                btend.Enabled = False
                MsgBox("任务名不能为空！", MsgBoxStyle.OkOnly, "提示")
                Exit Sub
            End If
            allasin = ""
            isworking = True
            btstart.Enabled = False
            task_name = taskname.Text
            If iscontinue.Checked Then
                Dim sqlstr = "select * from t_TaskList2 order by ObjectDBID desc limit 1;"
                Dim reader As Data.Common.DbDataReader = DB(sqlstr)
                If reader.HasRows Then
                    With reader.Read
                        starturl = CStr(reader.Item("Caurl"))
                    End With
                    If starturl = "" Then
                        starturl = listurl.Text
                    End If
                Else
                    MsgBox("记录为空！")
                End If
            Else
                starturl = listurl.Text
            End If
            Dim sqlstr2 = "select * from t_TaskList2 order by ObjectDBID desc limit 1;"
            Dim reader2 As Data.Common.DbDataReader = DB(sqlstr2)
            If reader2.HasRows Then
                With reader2.Read
                    allasin &= CStr(reader2.Item("Dpurl"))
                End With
            End If
            shuchu.Text = ""
            ListView1.Items.Clear()
            uploadxc = New System.Threading.Thread(New System.Threading.ParameterizedThreadStart(AddressOf caiji))
            uploadxc.Start()   '启动线程
            btend.Enabled = True

        Catch ex As Exception
            btend.Enabled = False
            btstart.Enabled = True
            isworking = False
            'MsgBox("已经停止", MsgBoxStyle.OkOnly, "提示")
            shuchu.Text &= "已经停止" & vbCrLf
        End Try
    End Sub
    Sub caiji()
        Try
            Dim i = 0
            Dim mydomain = getdomain(starturl)
            Do
                If isworking = False Then
                    Invoke(Sub()
                               btend.Enabled = False
                               btstart.Enabled = True
                               shuchu.Text &= "已经停止" & vbCrLf
                               Loadlist("")
                               MsgBox("已经停止", MsgBoxStyle.OkOnly, "提示")
                           End Sub)
                    Exit Sub
                End If

                CefWeb.Load(starturl)
                Application.DoEvents()
                Thread.Sleep(2000)
                Dim pagehtml = waitfor(CefWeb, starturl, "meow", "validatecaptcha", Me, "error/logo._ttd_.png", "ref=cs_404_logo")
                Dim page = "0"
                If InStr(starturl, "ref=sr_pg_") > 0 Then
                    Dim np = Split(starturl, "ref=sr_pg_")
                    page = np(UBound(np))
                End If
                Invoke(Sub()
                           shuchu.Text &= "开始抓取：" & starturl & vbCrLf
                       End Sub)


                If InStr(pagehtml, "<a class=""a-link-normal s-no-outline"" href=""") > 0 Then
                    Dim detailurls = Split(pagehtml, "<a class=""a-link-normal s-no-outline"" href=""")
                    'Console.WriteLine(detailurls.Count)
                    'Exit Sub
                    For r = 1 To UBound(detailurls)
                        Dim brand As String = ""
                        Dim isreg As String = "未知"
                        Dim asin As String = ""
                        Dim review As String = 0
                        Dim stars As String = 0
                        Dim status As String = "未知"
                        Dim nodebrowser As String = ""
                        Dim nodename As String = ""
                        Dim price As String = 0
                        Dim shipfee As String = 0
                        Dim totalprice As String = 0
                        Dim currency As String = "未知"
                        Dim bsr As String = 0
                        Dim ischina As String = "未知"
                        Dim totalmark As String = 0
                        Dim title As String = ""
                        Dim c_time As String = "未知"
                        Dim detailurl = mydomain & Replace(Split(detailurls(r), """>")(0), "amp;", "") & "&th=1&psc=1"
                        'Console.WriteLine(detailurl)
                        If InStr(allasin, detailurl) <= 0 Then
                            CefWeb.Load(detailurl)
                            Application.DoEvents()
                            Thread.Sleep(2000)
                            Dim html = waitfor(CefWeb, detailurl, "meow", "validatecaptcha", Me, "error/logo._ttd_.png", "ref=cs_404_logo")
                            If InStr(html, "add-to-cart-button") <= 0 And InStr(html, "cs_404_logo") <= 0 Then
                                status = "是"
                            Else
                                status = "否"
                            End If
                            brand = getbrand(html)
                            review = GetreviewNumbers(getreview(html))
                            stars = getstars(html)
                            asin = getasin(html)
                            title = gettitle(html)
                            bsr = getbsr(html)
                            nodebrowser = getnodebrowser(html)
                            nodename = getnodenodename(html)
                            price = getprice(html)
                            c_time = getc_time(html)
                            shipfee = getshipfee(html)
                            ischina = getfba(html)
                            currency = getcurrency(price)
                            price = GetNumbers(price)
                            totalprice = CDec(price) + CDec(shipfee)
                            If title <> "" Then
                                Dim totalmarkurl = mydomain & gettotalmarkurl(html)
                                'Console.WriteLine("totalmarkurl:" & totalmarkurl)
                                If totalmarkurl <> mydomain Then
                                    CefWeb.Load(totalmarkurl)
                                    Application.DoEvents()
                                    Thread.Sleep(2000)
                                    Dim totalmarkhtml = waitfor(CefWeb, totalmarkurl, "meow", "validatecaptcha", Me, "error/logo._ttd_.png", "ref=cs_404_logo")
                                    totalmark = GetreviewNumbers(gettotalmark(totalmarkhtml))
                                End If
                                If totalmark = 0 And ischina = "是" Then
                                    Console.WriteLine("totalmarkurl:" & totalmarkurl)
                                End If
                                If tradecookie <> "" And brand <> "" And brand.Length < 100 Then
                                    If brandlistname = "tmdn.org" Then
                                        Dim htmls = getnewhtml("https://www.tmdn.org/tmview/api/search/autocomplete/basicSearch?text=" & HttpUtility.UrlEncode(brand), "GET", "", tradecookie)
                                        If InStr(htmls, "here are your search results") > 0 Then
                                            isreg = "已注册"
                                        Else
                                            isreg = "未注册"
                                        End If
                                    End If
                                    If brandlistname = "ip51.com" Then
                                        Dim formdata = "{""keyWords"":[""" & brand & """],""sources"":[],""ncl"":[],""Keyword"":""" & brand & """,""status"":""0""}"
                                        Dim htmls = getnewhtml("https://www.ip51.com/api/brand/search", "POST", formdata, "", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36", "https://www.ip51.com/brand/search", "*/*", "application/json")
                                        If InStr(htmls, "{""brands"":[]}") > 0 Then
                                            isreg = "未注册"
                                        Else
                                            isreg = "已注册"
                                        End If
                                    End If
                                    If brandlistname = "trademarkia.com" Then
                                        Dim nurl = "https://www.trademarkia.com/trademarks-search.aspx?tn=" & HttpUtility.UrlEncode(brand)
                                        CefWeb.Load(nurl)
                                        'Thread.Sleep(1000)
                                        Console.WriteLine(nurl)
                                        Dim htmls = waitfor(CefWeb, nurl, "txt txt-lg")
                                        If InStr(htmls.ToLower, "here are your search results") > 0 Then
                                            isreg = "已注册"
                                        Else
                                            isreg = "未注册"
                                        End If
                                    End If
                                End If
                                i += 1
                                allasin &= detailurl
                                Dim t As New TaskList2
                                t.Asin = asin
                                t.Brand = trimsql(brand)
                                t.BSR = bsr
                                t.Caurl = trimsql(starturl)
                                t.Currency = currency
                                t.Nodebrowser = nodebrowser
                                t.Nodename = trimsql(nodename)
                                t.C_Time = c_time
                                t.IsReg = isreg
                                t.Dpurl = trimsql(detailurl)
                                t.IsChina = ischina
                                t.Page = page
                                t.Price = price
                                t.Review = review
                                t.Stars = stars
                                t.Status = status
                                t.Totalmark = totalmark
                                t.Totalprice = totalprice
                                t.Title = trimsql(title)
                                t.Shipfee = shipfee
                                t.Taskname = trimsql(task_name)
                                t.Add()
                                Invoke(Sub()
                                           Dim itm As ListViewItem
                                           itm = ListView1.Items.Add(ListView1.Items.Count + 1)
                                           itm.SubItems.AddRange({"", CStr(asin), CStr(detailurl), CStr(title), CStr(nodebrowser), CStr(nodename), CStr(review), CStr(stars), CStr(price), CStr(shipfee), CStr(totalprice), CStr(currency), CStr(bsr), CStr(brand), CStr(isreg), CStr(ischina), CStr(totalmark), CStr(c_time), CStr(task_name)})
                                           lbshuchu.Text = "当前已获取第：" & page & "页，获得产品数：" & i & "个"
                                       End Sub)
                            End If
                        End If
                    Next
                End If
                Dim splitstra = """ class=""s-pagination-item s-pagination-next"
                Dim splitstrb = "a-last""><a href="""
                If InStr(pagehtml, splitstra) > 0 Or InStr(pagehtml, splitstrb) > 0 Then
                    If InStr(pagehtml, splitstra) > 0 Then
                        Dim nextpagea = Split(pagehtml, splitstra)(0)
                        Dim nextpageb = Split(nextpagea, "<a href=""")
                        Dim nextpage = Replace(nextpageb(UBound(nextpageb)), "amp;", "")
                        starturl = mydomain & nextpage
                    End If
                    If InStr(pagehtml, splitstrb) > 0 Then
                        Dim nextpagea = Split(pagehtml, splitstrb)(1)
                        Dim nextpageb = Split(nextpagea, """>")(0)
                        Dim nextpage = Replace(nextpageb, "amp;", "")
                        starturl = mydomain & nextpage
                    End If
                    'Console.WriteLine(page & ":" & starturl)
                ElseIf InStr(pagehtml, "s-pagination-strip") > 0 Then
                    Invoke(Sub()
                               btend.Enabled = False
                               btstart.Enabled = True
                               shuchu.Text &= "已经停止" & vbCrLf
                               isworking = False
                           End Sub)
                    Exit Sub
                End If
                'Exit Sub
                'Console.WriteLine("aaaaa")
                Thread.Sleep(2000)
            Loop

        Catch ex As Exception
            'Console.WriteLine(ex)
            Invoke(Sub()
                       btend.Enabled = False
                       btstart.Enabled = True
                       shuchu.Text &= "已经停止" & vbCrLf
                       isworking = False
                       Loadlist("")
                       'MsgBox("已经停止", MsgBoxStyle.OkOnly, "提示")
                   End Sub)
        End Try
    End Sub

    Private Sub btend_Click(sender As Object, e As EventArgs) Handles btend.Click
        Try
            isworking = False
            If uploadxc.IsAlive Then
                uploadxc.Abort()
            End If
            GC.Collect()
            GC.WaitForFullGCApproach()
            btend.Enabled = False
            btstart.Enabled = True
            shuchu.Text &= "已经停止" & vbCrLf
            MsgBox("已经停止", MsgBoxStyle.OkOnly, "提示")
        Catch ex As Exception
            btend.Enabled = False
            btstart.Enabled = True
            isworking = False
            shuchu.Text &= "已经停止" & vbCrLf
            'MsgBox("已经停止", MsgBoxStyle.OkOnly, "提示")
        End Try
    End Sub


    Private Sub usecookie_CheckedChanged(sender As Object, e As EventArgs) Handles usecookie.CheckedChanged

    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        Try
            Dim url = "https://www.miwaimao.com/softlogin.php?UserName=" & UserNamelo & "&Version=" & Version & "&step=2&logintime=" & logintime
            Console.WriteLine(url)
            Dim html = getnewhtml(url)
            Console.WriteLine(html)
            If html = "8" Then
                MsgBox("您的账户已在别处登录，当前会话退出！")
                Timer1.Enabled = False
                End
            End If
        Catch ex As Exception
            MsgBox("登录异常，当前会话退出！")
            Timer1.Enabled = False
            End
        End Try
    End Sub
    Function GetTimeStamp()
        Dim ts As TimeSpan = DateTime.UtcNow - New DateTime(1970, 1, 1, 0, 0, 0, 0)
        Return Convert.ToInt64(ts.TotalSeconds).ToString()
    End Function
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles btend.Click
        Dim timeStamp = GetTimeStamp()
        Console.WriteLine(timeStamp)
    End Sub

    Private Sub Form3_TabStopChanged(sender As Object, e As EventArgs) Handles Me.TabStopChanged

    End Sub

    Private Sub Label3_Click(sender As Object, e As EventArgs)

    End Sub

    Private Sub TabPage1_Click(sender As Object, e As EventArgs) Handles TabPage1.Click

    End Sub

    Private Sub Button2_Click_1(sender As Object, e As EventArgs)
        'Dim html = getnewhtml("https://www.ecosia.org/search?q=site%3Aamazon.pl%20%2Fdp%2F%20%22Currently%20unavailable%22%20dress")
        'Dim html = getnewhtml("https://www.baidu.com")

        'AppendUserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36")
        ' ChangeUserAgent("Tiancao.net")
        'MsgBox(GetDefaultUserAgent)
        'WebBrowser1.Navigate("https://www.ecosia.org/search?q=site%3Aamazon.pl%20%2Fdp%2F%20%22Currently%20unavailable%22%20dress")




    End Sub

    Private Sub Button2_Click_2(sender As Object, e As EventArgs)
        'Dim t As New TaskList
        't.Add()
        'Console.WriteLine(getdomain(listurl.Text))
        Dim a = GetNumbers("fg32.24")
        Dim b = GetNumbers("%3.6")
        Dim c = CDec(a) + CDec(b)
        Console.WriteLine(c)
    End Sub


    Private Sub ListView1_DoubleClick(sender As Object, e As EventArgs) Handles ListView1.DoubleClick
        Try
            Dim url = ListView1.SelectedItems(0).SubItems(3).Text
            If IsNotWhiteSpace(url) Then
                System.Diagnostics.Process.Start(url)
            End If
        Catch ex As Exception

        End Try
    End Sub

    Private Sub Form3_Closed(sender As Object, e As EventArgs) Handles Me.Closed
        End
    End Sub

    Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
        Loadlist("")
    End Sub

    Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
        If CheckBox1.Checked = True Then
            For I = 0 To ListView2.Items.Count - 1
                ListView2.Items(I).Checked = True
            Next
        Else
            For I = 0 To ListView2.Items.Count - 1
                ListView2.Items(I).Checked = False
            Next
        End If
    End Sub

    Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
        Dim sqlstr = " 1=1"
        If js.Text <> "" Then
            sqlstr &= " and Status='" & js.Text & "'"
        End If
        If fbm.Text <> "" Then
            sqlstr &= " and IsChina='" & fbm.Text & "'"
        End If
        If sb.Text <> "" Then
            sqlstr &= " and IsReg='" & sb.Text & "'"
        End If
        If hb.Text <> "" Then
            sqlstr &= " and Currency='" & hb.Text & "'"
        End If
        If mytasklist.Text <> "" Then
            sqlstr &= " and Taskname='" & mytasklist.Text & "'"
        End If
        sqlstr &= " and Review>=" & pla.Value & " and Review<=" & plb.Value & " and Stars>=" & xja.Value & " and Stars<=" & xjb.Value & " and Totalprice>=" & zja.Value & " and Totalprice<=" & zjb.Value & " and Totalmark>=" & zha.Text & " and Totalmark<=" & zhb.Text
        Loadlist(sqlstr)
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Try
            For i = 0 To ListView2.Items.Count - 1
                If ListView2.Items(i).Checked = True Then
                    'DB.Execute("delete from tasklist where ID='" & ListView2.Items(i).SubItems(1).Text & "'")
                    Dim TaskList As TaskList2 = ListView2.Items(i).Tag
                    TaskList.Del()
                End If
            Next
            Loadlist("")
        Catch ex As Exception
            MsgBox("删除出错", MsgBoxStyle.OkOnly, "提示")
        End Try

    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        Try
            Dim TaskList As TaskList2
            TaskList.Execute("delete from t_TaskList2 where 1=1")
            Loadlist("")
        Catch ex As Exception
            MsgBox("删除出错", MsgBoxStyle.OkOnly, "提示")
        End Try
    End Sub

    Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
        'Try
        'Dim sqlstr = "select * from t_TaskList2 where 1=1"
        'sqlstr &= " and Review>=" & pla.Value & " and Review<=" & plb.Value & " and Stars>=" & xja.Value & " and Stars<=" & xjb.Value & " and IsReg='" & sb.Text & "' and Status='" & js.Text & "'"
        'sqlstr &= " order by Keyword desc;"
        'Dim str As String = ""
        'Dim reader As Data.Common.DbDataReader = DB(sqlstr)
        'Do While reader.Read
        '    str &= reader("Asin").ToString & vbCrLf
        'Loop
        'reader.Close()
        '    Dim str As String = ""
        '    For I = 0 To ListView2.Items.Count - 1
        '        If ListView2.Items(I).Checked = True Then
        '            str &= ListView2.Items(I).SubItems(1).Text & vbCrLf
        '        End If
        '    Next
        '    Dim filename = Format(Now(), "yyyy-MM-dd") & ".txt"
        '    My.Computer.FileSystem.WriteAllText(Application.StartupPath & "\" & filename, str, True, Encoding.Default)
        '    shuchu.Text &= "导出文件成功：" & Application.StartupPath & "\" & filename & vbCrLf
        '    MsgBox("导出成功，请在程序根目录下查看文件！", MsgBoxStyle.OkOnly, "提示")
        'Catch ex As Exception
        '    MsgBox("导出出错！", MsgBoxStyle.OkOnly, "提示")
        'End Try

        Try
            Dim str As String = "Asin,网址,产品标题,类目节点,所属类目,评论数,星级,售价,运费,总价,货币单位,BSR,品牌名,是否注册,是否自发货,店铺综合评分,上架时间" & vbCrLf
            For I = 0 To ListView2.Items.Count - 1
                If ListView2.Items(I).Checked = True Then
                    str &= ListView2.Items(I).SubItems(1).Text & ",""" & ListView2.Items(I).SubItems(2).Text & """,""" & ListView2.Items(I).SubItems(3).Text & """," & ListView2.Items(I).SubItems(4).Text & ",""" & ListView2.Items(I).SubItems(5).Text & """," & ListView2.Items(I).SubItems(6).Text & "," & ListView2.Items(I).SubItems(7).Text & "," & ListView2.Items(I).SubItems(8).Text & "," & ListView2.Items(I).SubItems(9).Text & "," & ListView2.Items(I).SubItems(10).Text & "," & ListView2.Items(I).SubItems(11).Text & "," & ListView2.Items(I).SubItems(12).Text & "," & ListView2.Items(I).SubItems(13).Text & "," & ListView2.Items(I).SubItems(14).Text & "," & ListView2.Items(I).SubItems(15).Text & "," & ListView2.Items(I).SubItems(16).Text & ",""" & ListView2.Items(I).SubItems(17).Text & """" & vbCrLf
                End If
            Next

            Dim filename = Format(Now(), "yyyy-MM-dd") & ".csv"
            My.Computer.FileSystem.WriteAllText(Application.StartupPath & "\" & filename, str, True, Encoding.Default)
            shuchu.Text &= "导出文件成功：" & Application.StartupPath & "\" & filename
            MsgBox("导出成功，请在程序根目录下查看文件！", MsgBoxStyle.OkOnly, "提示")
        Catch ex As Exception
            MsgBox("导出出错！", MsgBoxStyle.OkOnly, "提示")
        End Try
    End Sub

    Private Sub ListView2_SelectedIndexChanged(sender As Object, e As EventArgs)

    End Sub

    Private Sub ListView2_ItemSelectionChanged(sender As Object, e As ListViewItemSelectionChangedEventArgs)

    End Sub

    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        Try
            Dim str As String = "Asin,网址,产品标题,类目节点,所属类目,评论数,星级,售价,运费,总价,货币单位,BSR,品牌名,是否注册,是否自发货,店铺综合评分,上架时间" & vbCrLf
            Dim sql As String = "select * from t_TaskList2 where 1=1"
            If js.Text <> "" Then
                sql &= " and Status='" & js.Text & "'"
            End If
            If fbm.Text <> "" Then
                sql &= " and IsChina='" & fbm.Text & "'"
            End If
            If sb.Text <> "" Then
                sql &= " and IsReg='" & sb.Text & "'"
            End If
            If hb.Text <> "" Then
                sql &= " and Currency='" & hb.Text & "'"
            End If
            If mytasklist.Text <> "" Then
                sql &= " and Taskname='" & mytasklist.Text & "'"
            End If
            sql &= " and Review>=" & pla.Value & " and Review<=" & plb.Value & " and Stars>=" & xja.Value & " and Stars<=" & xjb.Value & " and Totalprice>=" & zja.Value & " and Totalprice<=" & zjb.Value & " and Totalmark>=" & zha.Text & " and Totalmark<=" & zhb.Text
            Dim reader As Data.Common.DbDataReader = DB(sql)
            Do While reader.Read
                str &= reader("Asin").ToString & "," & reader("Dpurl").ToString & ",""" & reader("Title").ToString & """," & reader("Nodebrowser").ToString & ",""" & reader("Nodename").ToString & """," & reader("Review").ToString & "," & reader("Stars").ToString & "," & reader("Price").ToString & "," & reader("Shipfee").ToString & "," & reader("Totalprice").ToString & "," & reader("Currency").ToString & "," & reader("BSR").ToString & "," & reader("Brand").ToString & "," & reader("IsReg").ToString & "," & reader("IsChina").ToString & "," & reader("Totalmark").ToString & ",""" & reader("C_Time").ToString & """" & vbCrLf
            Loop
            reader.Close()
            Dim filename = Format(Now(), "yyyy-MM-dd") & ".csv"
            My.Computer.FileSystem.WriteAllText(Application.StartupPath & "\" & filename, str, True, Encoding.Default)
            shuchu.Text &= "导出文件成功：" & Application.StartupPath & "\" & filename
            MsgBox("导出成功，请在程序根目录下查看文件！", MsgBoxStyle.OkOnly, "提示")
        Catch ex As Exception
            MsgBox("导出出错！", MsgBoxStyle.OkOnly, "提示")
        End Try
    End Sub


    Private Sub Button2_Click_3(sender As Object, e As EventArgs) Handles Button2.Click
        'Dim MyDateTime1 As DateTime = DateTime.Parse("5 sierpnia 2021")
        'Dim datestr = Format("5 sierpnia 2021", "yyyy/MM/dd")
        'Dim culture As CultureInfo = New CultureInfo("en-US")
        'Dim dates As DateTime = DateTime.ParseExact("April 11, 2021", "dd.MM.yyyy", culture)
        'Dim MyDateTime1 As DateTime = DateTime.Parse("April 11, 2021")
        'Dim MyDateTime2 As DateTime = DateTime.Parse("5 sierpnia 2021")
        'Console.WriteLine(MyDateTime2)
        Dim url = "https://sellercentral.amazon.co.uk/fba/profitabilitycalculator/productmatches?searchKey=B08JLWR8MC&searchType=keyword&language=en_US&profitcalcToken=g1bZDQQw8Ql0WkALh4hI1JDs+9wDzpv2XoSQa7L9lHfTAAAAAgAAAABh6stScmF3AAAAAPiBYUbAhV311Y/7XVH9gA=="
        'Dim html = getnewhtml(url, "GET", "", "", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36", "", "application/json;charset=UTF-8", "application/json;charset=UTF-8")
        Dim newurl = "https://sellercentral.amazon.com/fba/profitabilitycalculator/getafnfee?profitcalcToken=g6HCRsYy/YRJMdyGq6F7aAavS0ZwbK/GNKb2qYJBcwEtAAAAAgAAAABh7qH/cmF3AAAAAPiBYUbAhV311Y/7XVH9gA=="
        'Dim html = Sy.Net.GetHtml(url)

        Dim postdata = "{""productInfoMapping"":{""isWhiteGloveRequired"":false,""weightUnitString"":""pounds"",""subCategory"":""19304876"",""fnsku"":"""",""dimensionUnit"":""inches"",""link"":""http://www.amazon.com/gp/product/B08DTWLKBN/ref=silver_xx_cont_revecalc"",""binding"":""unknown_binding"",""title"":""Children Cotton Crew Socks For Girl Boy Kids Toddler Gift Fashion Cute Cartoon Animal Stocking Stuffer Unicorn Socks 6 Pack (Unicorn-I, 5-8 Years Old)"",""dimensionUnitString"":""inches"",""price"":0,""imageUrl"":""https://m.media-amazon.com/images/I/51d-280PRSL._SL120_.jpg"",""height"":10.91,""isAfn"":false,""gl"":""gl_apparel"",""TRexId"":"""",""length"":2.36,""isAsinLimits"":true,""weight"":0.3704,""originalUrl"":"""",""productGroup"":"""",""width"":6.81,""thumbStringUrl"":""https://m.media-amazon.com/images/I/51d-280PRSL._SL120_SL80_.jpg"",""asin"":""B08DTWLKBN"",""encryptedMarketplaceId"":"""",""weightUnit"":""pounds""},""afnPriceStr"":0,""mfnPriceStr"":0,""mfnShippingPriceStr"":0,""currency"":""USD"",""marketPlaceId"":""ATVPDKIKX0DER"",""hasFutureFee"":false,""futureFeeDate"":""2022-01-21 08:00:00"",""hasTaxPage"":true}"
        Dim html = Sy.Net.Post(newurl, postdata)
        Console.WriteLine(html)
    End Sub

    Private Sub ListView1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListView1.SelectedIndexChanged

    End Sub

    Private Sub ListView2_SelectedIndexChanged_1(sender As Object, e As EventArgs) Handles ListView2.SelectedIndexChanged

    End Sub

    Private Sub ListView2_DoubleClick(sender As Object, e As EventArgs) Handles ListView2.DoubleClick
        Try
            Dim url = ListView2.SelectedItems(0).SubItems(2).Text
            If IsNotWhiteSpace(url) Then
                System.Diagnostics.Process.Start(url)
            End If
        Catch ex As Exception

        End Try
    End Sub

    Private Sub usecookie_Click(sender As Object, e As EventArgs) Handles usecookie.Click
        If listurl.Text = "" Then
            MsgBox("请先输入列表页网址", MsgBoxStyle.OkOnly, "提示")
            usecookie.Checked = False
            Exit Sub
        End If
        If usecookie.Checked Then
            Form4.Show()
        End If
    End Sub

    'Private Sub CefWeb_DocumentCompleted(sender As CefBrowser, DocumentCompletedEventArgs As DocumentCompletedEventArgs) Handles CefWeb.DocumentCompleted
    '    Dim page = DocumentCompletedEventArgs.GetDomHtml()
    '    Console.WriteLine(page)

    'End Sub
End Class